from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-23 14:06:21.139217
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 23, Oct, 2022
Time: 14:06:28
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.7999
Nobs: 818.000 HQIC: -51.1191
Log likelihood: 10632.7 FPE: 5.16384e-23
AIC: -51.3178 Det(Omega_mle): 4.62891e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.294023 0.052045 5.649 0.000
L1.Burgenland 0.108670 0.035197 3.087 0.002
L1.Kärnten -0.106428 0.018749 -5.677 0.000
L1.Niederösterreich 0.210850 0.073649 2.863 0.004
L1.Oberösterreich 0.101488 0.070602 1.437 0.151
L1.Salzburg 0.249932 0.037460 6.672 0.000
L1.Steiermark 0.037664 0.049089 0.767 0.443
L1.Tirol 0.106415 0.039806 2.673 0.008
L1.Vorarlberg -0.058433 0.034235 -1.707 0.088
L1.Wien 0.060236 0.062971 0.957 0.339
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063941 0.107681 0.594 0.553
L1.Burgenland -0.033032 0.072823 -0.454 0.650
L1.Kärnten 0.047837 0.038791 1.233 0.218
L1.Niederösterreich -0.172892 0.152379 -1.135 0.257
L1.Oberösterreich 0.385184 0.146075 2.637 0.008
L1.Salzburg 0.286118 0.077505 3.692 0.000
L1.Steiermark 0.105262 0.101566 1.036 0.300
L1.Tirol 0.313765 0.082359 3.810 0.000
L1.Vorarlberg 0.025444 0.070833 0.359 0.719
L1.Wien -0.015024 0.130288 -0.115 0.908
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189071 0.026709 7.079 0.000
L1.Burgenland 0.090489 0.018063 5.010 0.000
L1.Kärnten -0.008426 0.009622 -0.876 0.381
L1.Niederösterreich 0.264578 0.037797 7.000 0.000
L1.Oberösterreich 0.125921 0.036233 3.475 0.001
L1.Salzburg 0.048435 0.019225 2.519 0.012
L1.Steiermark 0.017260 0.025193 0.685 0.493
L1.Tirol 0.094743 0.020429 4.638 0.000
L1.Vorarlberg 0.059279 0.017570 3.374 0.001
L1.Wien 0.119640 0.032317 3.702 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107675 0.027382 3.932 0.000
L1.Burgenland 0.044730 0.018518 2.415 0.016
L1.Kärnten -0.016177 0.009864 -1.640 0.101
L1.Niederösterreich 0.193166 0.038748 4.985 0.000
L1.Oberösterreich 0.293979 0.037145 7.914 0.000
L1.Salzburg 0.116088 0.019709 5.890 0.000
L1.Steiermark 0.099824 0.025827 3.865 0.000
L1.Tirol 0.116996 0.020943 5.586 0.000
L1.Vorarlberg 0.070684 0.018012 3.924 0.000
L1.Wien -0.027482 0.033131 -0.830 0.407
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123601 0.049753 2.484 0.013
L1.Burgenland -0.050837 0.033647 -1.511 0.131
L1.Kärnten -0.040460 0.017923 -2.257 0.024
L1.Niederösterreich 0.169543 0.070406 2.408 0.016
L1.Oberösterreich 0.137625 0.067493 2.039 0.041
L1.Salzburg 0.285519 0.035811 7.973 0.000
L1.Steiermark 0.033476 0.046928 0.713 0.476
L1.Tirol 0.165963 0.038054 4.361 0.000
L1.Vorarlberg 0.104687 0.032728 3.199 0.001
L1.Wien 0.072805 0.060198 1.209 0.227
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059491 0.039369 1.511 0.131
L1.Burgenland 0.039429 0.026625 1.481 0.139
L1.Kärnten 0.050765 0.014183 3.579 0.000
L1.Niederösterreich 0.225472 0.055712 4.047 0.000
L1.Oberösterreich 0.282071 0.053407 5.282 0.000
L1.Salzburg 0.051609 0.028337 1.821 0.069
L1.Steiermark -0.007836 0.037134 -0.211 0.833
L1.Tirol 0.149884 0.030112 4.978 0.000
L1.Vorarlberg 0.071105 0.025898 2.746 0.006
L1.Wien 0.078927 0.047635 1.657 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174375 0.047067 3.705 0.000
L1.Burgenland -0.005516 0.031831 -0.173 0.862
L1.Kärnten -0.061167 0.016956 -3.608 0.000
L1.Niederösterreich -0.083590 0.066605 -1.255 0.209
L1.Oberösterreich 0.192833 0.063849 3.020 0.003
L1.Salzburg 0.057638 0.033877 1.701 0.089
L1.Steiermark 0.229676 0.044394 5.174 0.000
L1.Tirol 0.494949 0.035999 13.749 0.000
L1.Vorarlberg 0.049939 0.030961 1.613 0.107
L1.Wien -0.047112 0.056949 -0.827 0.408
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160138 0.054004 2.965 0.003
L1.Burgenland -0.011356 0.036522 -0.311 0.756
L1.Kärnten 0.065891 0.019455 3.387 0.001
L1.Niederösterreich 0.200531 0.076421 2.624 0.009
L1.Oberösterreich -0.060532 0.073260 -0.826 0.409
L1.Salzburg 0.217223 0.038870 5.588 0.000
L1.Steiermark 0.113525 0.050937 2.229 0.026
L1.Tirol 0.077826 0.041305 1.884 0.060
L1.Vorarlberg 0.124610 0.035524 3.508 0.000
L1.Wien 0.114070 0.065342 1.746 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.352148 0.031484 11.185 0.000
L1.Burgenland 0.005997 0.021292 0.282 0.778
L1.Kärnten -0.023616 0.011342 -2.082 0.037
L1.Niederösterreich 0.224319 0.044553 5.035 0.000
L1.Oberösterreich 0.174221 0.042709 4.079 0.000
L1.Salzburg 0.048212 0.022661 2.128 0.033
L1.Steiermark -0.016536 0.029696 -0.557 0.578
L1.Tirol 0.109568 0.024080 4.550 0.000
L1.Vorarlberg 0.073822 0.020710 3.565 0.000
L1.Wien 0.053006 0.038093 1.391 0.164
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041477 0.152012 0.189497 0.158193 0.124234 0.114468 0.065760 0.226551
Kärnten 0.041477 1.000000 -0.002598 0.129718 0.042159 0.096145 0.429555 -0.053032 0.101179
Niederösterreich 0.152012 -0.002598 1.000000 0.337447 0.155291 0.300650 0.111515 0.184264 0.328353
Oberösterreich 0.189497 0.129718 0.337447 1.000000 0.232771 0.332900 0.173190 0.172872 0.263347
Salzburg 0.158193 0.042159 0.155291 0.232771 1.000000 0.146899 0.129103 0.149276 0.134928
Steiermark 0.124234 0.096145 0.300650 0.332900 0.146899 1.000000 0.153952 0.141054 0.079433
Tirol 0.114468 0.429555 0.111515 0.173190 0.129103 0.153952 1.000000 0.115385 0.155340
Vorarlberg 0.065760 -0.053032 0.184264 0.172872 0.149276 0.141054 0.115385 1.000000 0.007641
Wien 0.226551 0.101179 0.328353 0.263347 0.134928 0.079433 0.155340 0.007641 1.000000